var ws_url = 'ws://140.143.228.54:81';
var live_ws = new WebSocket(ws_url);
live_ws.onopen=function (evt) {
    console.log('ws connect success');
    live_ws.send('send to server');
};

live_ws.onmessage=function (evt) {
    console.log(evt.data);
    var data = JSON.parse(evt.data);
    console.log('======服务器推送过来的消息====start');
    console.log(data);
    console.log('======服务器推送过来的消息====end');
    if (data.method == 'pushLive') {
        buildLive(data.data);
    }
    if (data.method == 'chat') {

    }
};

live_ws.onclose=function (evt) {
    console.log('ws connect has closed');
};

function buildLive(obj) {
    var type_name = '';
    if (obj.type == 1) type_name = '第一节';
    if (obj.type == 2) type_name = '第er节';
    if (obj.type == 3) type_name = '第san节';
    if (obj.type == 4) type_name = '第si节';
    var html = '<div class="frame"><h3 class="frame-header">';
    html += '<i class="icon iconfont icon-shijian"></i>'+type_name+' '+obj.score+'</h3>';
    html += '<div class="frame-item"><span class="frame-dot"></span><div class="frame-item-author">';
    html += '<img src="'+obj.logo+'" width="20px" height="20px" /> '+obj.title+'</div>';
    html += '<p>'+obj.time +' &nbsp;'+obj.content+'</p>';
    if (obj.image) {
        html += '<p><img src="'+obj.image+'" width="40%" /></p>';
    }
    html += '</div></div>'
    $('#match-result').prepend(html);

}

function buildChat(obj) {

}